﻿using Batman.Jianbei.Forum.Areas.Forum.Responses;
using Batman.Jianbei.Forum.Core.Domains.Dicts;
using Batman.Jianbei.Forum.Core.Domains.Posts;
using Batman.Jianbei.Forum.Core.Domains.Users;
using System.Collections.Generic;
using System.Linq;

namespace Batman.Jianbei.Forum.Areas.Forum.Converts
{
    public static class PostExtension
    {
        public static PostFlowItem ToPostFlowItem(this Post post)
        {
            PostFlowItem item = new PostFlowItem();

            item.PostId = post.Id;
            item.PostTitle = post.Title;
            item.PostContent = post.PostContent;
            item.PostCreateAt = post.CreateAt;
            // todo: 头像赋值

            WeixinUser wxUser = post.WxUser; // 微信用户信息

            if (wxUser != null)
            {
                item.WxUId = wxUser.Id;
                item.Avatar = wxUser.Avatar;
                item.WxUName = wxUser.Nickname;
            }

            Topic topic = post.Topic; // 话题

            if (topic != null)
            {
                item.TId = topic.Id;
                item.TName = topic.Name;

                Partition partition = topic.Partition; // 分区

                if (partition != null)
                {
                    item.TId = partition.Id;
                    item.TName = partition.Name;
                }
            }

            List<PostImg> images = post.Imgs;
            if (images != null && images.Count > 0)
            {
                item.images = images.Select(t => t.Img).ToList();
            }

            return item;
        }
    }
}
